﻿Imports System.Collections.Generic
Imports System.Linq
Partial Class custProfile
    Inherits System.Web.UI.Page
    Dim cUser As OneCall.User.AuthUser

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        cUser = New OneCall.User.AuthUser(Request, Response)

        If cUser.isActiveSession() = False Then
            Response.Redirect("Login.aspx")
        End If

        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
        Dim uid = cUser.GetUserID()
        Dim cCustomer As OneCall.DataModel.Customer = (From p In SQLDB.Customers Where p.Customer_ID = uid Select p).ToArray(0)

        txtUserName.Text = cCustomer.Customer_UserName
        txtPassword.Text = "**********"
        txtEmailID.Text = cCustomer.Customer_EmailID
        txtMobile.Text = cCustomer.Customer_Mobile
        txtFirstName.Text = cCustomer.Customer_FirstName
        txtLastName.Text = cCustomer.Customer_LastName
        txtAddress.Text = cCustomer.Customer_Address
        txtCity.Text = cCustomer.Customer_City
        txtState.Text = cCustomer.Customer_State
        txtPin.Text = cCustomer.Customer_Pin
        txtCountry.Text = cCustomer.Customer_Country


        cCustomer = Nothing
        SQLDB.Dispose()

        'Dim img As New Captcha("hello", 100, 80)


    End Sub

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

        If txtFirstName.Text = "" Then
            lblfnamemessage.Visible = True
            Exit Sub
        Else
            lblfnamemessage.Visible = False
        End If

        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
        Dim uid = cUser.GetUserID()
        Dim cCustomer As OneCall.DataModel.Customer = (From p In SQLDB.Customers Where p.Customer_ID = uid Select p).ToArray(0)

        cCustomer.Customer_FirstName = txtFirstName.Text
        cCustomer.Customer_LastName = txtLastName.Text
        cCustomer.Customer_Address = txtAddress.Text
        cCustomer.Customer_City = txtCity.Text
        cCustomer.Customer_State = txtState.Text
        cCustomer.Customer_Pin = txtPin.Text
        cCustomer.Customer_Country = txtCountry.Text

        SQLDB.SaveChanges()
        cCustomer = Nothing
        SQLDB.Dispose()

    End Sub
End Class
